package com.ch.home.service.serviceImpl.gameServiceImpl;

import com.ch.home.bean.GameInfo;
import com.ch.home.mapper.gameMapper.GameInfoMapper;
import com.ch.home.service.serviceInterface.gameSerivce.GameInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by CHEN on 2019/9/1.
 */
@Service
public class GameInfoServiceImpl implements GameInfoService {


    @Autowired
    GameInfoMapper gameInfoMapper;

    @Override
    public HashMap addResult(GameInfo gameInfo) {

        HashMap<Object,Object> result = new HashMap();
        int re =gameInfoMapper.addResult(gameInfo);

        if (re == 1) {
            result.put("message", "success");
        } else {
            result.put("message", "fail");
        }

        return result;

    }

    @Override
    public HashMap updateResult(GameInfo gameInfo) {

        HashMap<Object,Object> result = new HashMap();
        int re =gameInfoMapper.updateResult(gameInfo);

        if (re == 1) {
            result.put("message", "success");
        } else {
            result.put("message", "fail");
        }

        return result;



    }

    @Override
    public HashMap getGameResultByCondition(GameInfo gameInfo) {

        HashMap<Object,Object> result = new HashMap();

        ArrayList<GameInfo> gameInfos = gameInfoMapper.getGameResultByCondition(gameInfo);

        if (gameInfos.size( ) > 0) {
            result.put("message", "success");
        } else {
            result.put("message", "fail");
        }

        result.put("value", gameInfos);
        return result;
    }
}
